package com.talent.core.protocol.mqtt.codec.decoder;

import com.talent.core.protocol.mqtt.model.fix.TlMqttFixedHead;
import com.talent.core.protocol.mqtt.model.request.TlMqttPubRelReq;
import com.talent.core.protocol.mqtt.model.variable.TlMqttPubRelVariableHead;
import io.netty.buffer.ByteBuf;

/**
 * @ClassName：TlConnectDecoder
 * @Author: hszhou
 * @Date: 2024/11/30 15:12
 * @Description: 必须描述类做什么事情, 实现什么功能
 */
public class TlMqttPubRelDecoder {

    public TlMqttPubRelReq build(ByteBuf buf, int type, int remainingLength){
        TlMqttFixedHead fixedHead = decodeFixedHeader( type, remainingLength);
        TlMqttPubRelVariableHead variableHead = decodeVariableHeader(buf);
        return new TlMqttPubRelReq(fixedHead,variableHead);
    }

    TlMqttFixedHead decodeFixedHeader(int type,int remainingLength) {
        TlMqttFixedHead fixedHead =new TlMqttFixedHead();
        int messageType = type >> 4;
        fixedHead.setMessageType(messageType);
        fixedHead.setType(type);
        fixedHead.setLength(remainingLength);
        return fixedHead;
    }


    TlMqttPubRelVariableHead decodeVariableHeader(ByteBuf buf) {
        TlMqttPubRelVariableHead variableHead=new TlMqttPubRelVariableHead();
        int messageId = buf.readUnsignedShort();
        variableHead.setMessageId(messageId);
        return variableHead;
    }



}
